//
//  MHBlackListViewController.m
//  MiaoCircle
//
//  Created by Xuzhengrong on 2018/5/5.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHBlackListViewController.h"
#import "MHCommonCell.h"
#import "MHAlertTableViewView.h"
#import "MHAlertTableViewModel.h"
#import "MHCircleMember.h"
#import "MHBlackListViewModel.h"

@interface MHBlackListViewController ()
@property(nonatomic, strong)  MHBlackListViewModel *viewModel;
@end

@implementation MHBlackListViewController
@dynamic viewModel;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)configureCell:(MHCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object{
 
     __weak __typeof(self)weakSelf = self;
    MHCommonItemViewModel *model =  (MHCommonItemViewModel *)object;
    
    if(self.viewModel.info.identType != MHCircleIdentityTypeGuestMember &&  self.viewModel.info.identType != MHCircleIdentityTypeGuest)
    {
        MHCircleMember *circleMember = (MHCircleMember *)model.model;
        model.operation = ^{
            MHAlertTableViewModel *cancelBlack = [MHAlertTableViewModel new];
            cancelBlack.titile = @"解除拉黑";
            
            cancelBlack.operationBlock = ^{
                
                [[self.viewModel.cancelBlackMemberCommand execute:@(circleMember.autoId)] subscribeNext:^(id x) {
                    [self.viewModel.blackList removeObject:circleMember];
                    [self.viewModel willChangeValueForKey:@"blackList"];
                    [self.viewModel didChangeValueForKey:@"blackList"];
                }];
                [weakSelf.zh_popupController dismiss];
            };
            
            MHAlertTableViewModel *remove = [MHAlertTableViewModel new];
            remove.titile = @"移除该成员";
            remove.operationBlock = ^{
                [self showAlertViewControllerWithTitle:@"移除该成员" content:@"确定移除该成员?" comfirmblock:^{
                    [[weakSelf.viewModel.removeMemberCommand execute:@(circleMember.autoId)] subscribeNext:^(id x) {
                        [self.viewModel.blackList removeObject:circleMember];
                        [self.viewModel willChangeValueForKey:@"blackList"];
                        [self.viewModel didChangeValueForKey:@"blackList"];
                    }];
                    [weakSelf.zh_popupController dismiss];
                }dissMissBlock:^{
                    [weakSelf.zh_popupController dismiss];
                }];
                
            };
            MHAlertTableViewView *tableView  = [[MHAlertTableViewView alloc] initWithDataSource:@[cancelBlack,remove] andHeaderData:circleMember];
            tableView.width = self.view.width * 0.8;
            weakSelf.zh_popupController = [zhPopupController new];
            [weakSelf.zh_popupController presentContentView:tableView];
        };
    }
    
    [cell bindViewModel:object];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
